import wrapRequest from "../../../utils/request"
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		products: [
			// {
			// 	img: "http://apiv1.frozenhu.cn/uploads/file/84a135ebb9f289e55b0dfe02d5b92778_20240430181021.png",
			// 	text: "任天堂(Nintendo) Switch NS掌上游戏机 NS家用体感游戏机掌上...",
			// 	price: "￥3289.00",
			// },
			// {
			// 	img: "http://apiv1.frozenhu.cn/uploads/file/84a135ebb9f289e55b0dfe02d5b92778_20240430181021.png",
			// 	text: "任天堂(Nintendo) Switch NS掌上游戏机 NS家用体感游戏机掌上...",
			// 	price: "￥3289.00",
			// },
		],
	},
	onLoad(options) {
		var that = this
		wrapRequest('/v1.0/huichun/mine/collect', 'GET', {
			success: function (res) {
				var product = []
				if (res.data?.data) {
					res.data.data.map(item => {
						product.push({
							id: item.id,
							img: item.pic,
							text: item.name.slice(0, 12) + "...",
							price: "￥" + item.price,
							is_collect: item.is_collect,
						})
					})
					that.setData({
						products: product
					})
				}
			}
		})
	},
	onCollect(e) {
		var that = this
		const productId = e.currentTarget.dataset.product_id
		const collect = e.currentTarget.dataset.collect
		const i1 = e.currentTarget.dataset.i1
		var products = this.data.products
		wrapRequest('/v1.0/huichun/mine/collect', 'POST', {
			data: {
				product_id: productId,
				collect: collect,
			},
			success: function (res) {
				products[i1].is_collect = collect
				that.setData({
					products: products,
				})
			}
		})
	},
})